package com.video;

import android.app.Fragment;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.MediaController;
import android.widget.VideoView;

import com.app.net.NetHelper;
import com.example.com.skills_utf8.ProgressBar1Activity;
import com.example.com.skills_utf8.R;
import com.google.gson.Gson;

import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;

import java.net.URI;
import java.util.ArrayList;
import java.util.List;

import bean.waqu.SearchGuitar;



//
public class VideoActivityFragment extends Fragment {


    Adapter adapter = new Adapter();

    List<String> listdata = new ArrayList<String>();




    public VideoActivityFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {


        View view = inflater.inflate(R.layout.fragment_video, container, false);

        ListView listview = (ListView)view.findViewById(R.id.listview);



        for(int i =0; i<1; i++) {
           // listdata.add("http://211.144.82.110/youku/67754C429723F8246D0E306A9A/0300020100558404D4BB89003E88035A39323F-3CBE-D54B-E1C9-7D2DDE3BFCD1.flv");
           // listdata.add("http://218.242.102.35/youku/6774C3207274083D264F2F3362/0300020100557A850368E52DC8A558E48FC60C-3E8E-35B4-CA41-8A236332DBBC.flv");

            listdata.add("http://vss.waqu.com/r58x2enkclmy72dm/preview/10.mp4");
        }


        listview.setAdapter(adapter);





        return view;

    }


    class Adapter extends BaseAdapter
    {

        @Override
        public int getCount() {
            return listdata.size();
        }

        @Override
        public Object getItem(int position) {
            return listdata.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            if(convertView == null){
                convertView = getActivity().getLayoutInflater().inflate(R.layout.layout_video, null);
            }

            String url = listdata.get(position);
            Uri uri = Uri.parse(url);



            // 原声最基本的播放视频
            MediaController controller = new MediaController(getActivity());

            VideoView vv_content = (VideoView) convertView.findViewById(R.id.vv_content);
            vv_content.setMediaController(controller); // 使有控制条
            vv_content.setVideoURI( uri );
            vv_content.start();

            return convertView;
        }
    }





}
